package com.xjlsoft.weather.service.impl;

import com.xjlsoft.weather.common.util.DataUtil;
import com.xjlsoft.weather.common.util.DateUtil;
import com.xjlsoft.weather.dto.DataAvgDto;
import com.xjlsoft.weather.entity.AerosolAvg;
import com.xjlsoft.weather.entity.AerosolData;
import com.xjlsoft.weather.entity.GroundAvg;
import com.xjlsoft.weather.entity.GroundData;
import com.xjlsoft.weather.enums.AvgFlagEnum;
import com.xjlsoft.weather.enums.DataTypeEnum;
import com.xjlsoft.weather.mapper.AerosolAvgMapper;
import com.xjlsoft.weather.mapper.AerosolDataMapper;
import com.xjlsoft.weather.service.AerosolAvgService;
import com.xjlsoft.weather.util.WeatherDataUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.sql.Timestamp;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 大气数据 平均数据 表 服务实现类
 * </p>
 *
 * @author zhangbanglong
 * @since 2020-08-19
 */
@Service
public class AerosolAvgServiceImpl extends ServiceImpl<AerosolAvgMapper, AerosolAvg> implements AerosolAvgService {

	@Autowired
	private AerosolAvgMapper aerosolAvgMapper;
	
	@Autowired
	private AerosolDataMapper aerosolDataMapper;

	/**
	 * 2016 ---2020 有数据
	 */
	@Override
	public int saveAvgDay(Date dateStart,Date dateEnd) {

		int flag = 0;
		while (true) {

			Map<String, String> map = WeatherDataUtil.getYearMonDayStr(dateStart);

			String result = aerosolAvgMapper.getAerosolAvgDay(map.get("year"), map.get("mon"), map.get("day"));

			List<String> listStr = WeatherDataUtil.strToArrayList(result, "#");
			AerosolAvg ga = new AerosolAvg(listStr.get(0), listStr.get(1), listStr.get(2), listStr.get(3),
					listStr.get(4), listStr.get(5), listStr.get(6), listStr.get(7), listStr.get(8), listStr.get(9),
					listStr.get(10), listStr.get(11));
			ga.setDay_avg_id(IdWorker.getIdStr());
			ga.setCreate_time(DataUtil.getCurrenTimestamp());
			ga.setData_type("day");
			ga.setYear(map.get("year"));
			ga.setMon(map.get("mon"));
			ga.setDay(map.get("day"));
			ga.setDate_time(new Timestamp(dateStart.getTime()));
			ga.setDate_str(DateUtil.DateToString(dateStart, "yyyy-MM-dd"));

			Date nextDate = WeatherDataUtil.calculateEndDate(dateStart, 1);
			if (nextDate.after(dateEnd)) {
				break;
			}
			int jflag = aerosolAvgMapper.insert(ga);
			flag = flag + jflag;
			
			
			
			List<String> list=aerosolDataMapper.getIdByYearMonDay(map.get("year"), map.get("mon"), map.get("day"));
			if(list.size()>0){
				
				Iterator<String> iter=list.iterator();
				while(iter.hasNext()){
					String groundDataId=iter.next();
					
					AerosolData gd=new AerosolData();
					gd.setAeroso_id(groundDataId);
					gd.setAvg_flag(AvgFlagEnum.SUCCESS.getValue());
					//更新  ground de avgFlag
					aerosolDataMapper.updateById(gd);
				}
			}
			
			dateStart = nextDate;

		}

		return flag;

	}

	@Override
	public int saveAvgMon(String year,String mon) {
		
		String result = aerosolAvgMapper.getAerosolAvgMon(year,mon);

		
		String monStr=WeatherDataUtil.getMonMMStr(Integer.valueOf(mon));
		
		
		Date dateStart = DateUtil.StringToDate( year+"-"+monStr, "yyyy-MM");


		List<String> listStr = WeatherDataUtil.strToArrayList(result, "#");
		AerosolAvg ga = new AerosolAvg(listStr.get(0), listStr.get(1), listStr.get(2), listStr.get(3),
				listStr.get(4), listStr.get(5), listStr.get(6), listStr.get(7), listStr.get(8), listStr.get(9),
				listStr.get(10), listStr.get(11));
		ga.setDay_avg_id(IdWorker.getIdStr());
		ga.setCreate_time(DataUtil.getCurrenTimestamp());
		ga.setData_type(DataTypeEnum.Mon.getValue());
		ga.setYear(year);
		ga.setMon(String.valueOf(mon));
		ga.setDate_time(new Timestamp(dateStart.getTime()));
		ga.setDate_str(year + "-" + monStr);

		// Date nextDate=WeatherDataUtil.calculateEndDate(dateStart, 1);

		int jflag = aerosolAvgMapper.insert(ga);

	return jflag;

	}

	@Override
	public int saveAvgYear(String yearStr) {
		int flag = 0;
		String result = aerosolAvgMapper.getAerosolAvgYear(yearStr);
		
		Date dateStart = DateUtil.StringToDate( yearStr,"yyyy");

		List<String> listStr = WeatherDataUtil.strToArrayList(result, "#");
		AerosolAvg ga = new AerosolAvg(listStr.get(0), listStr.get(1), listStr.get(2), listStr.get(3), listStr.get(4),
				listStr.get(5), listStr.get(6), listStr.get(7), listStr.get(8), listStr.get(9), listStr.get(10),
				listStr.get(11));
		ga.setDay_avg_id(IdWorker.getIdStr());
		ga.setCreate_time(DataUtil.getCurrenTimestamp());
		ga.setData_type(DataTypeEnum.Year.getValue());
		ga.setYear(yearStr);
		ga.setDate_str(yearStr);
		ga.setDate_time(new Timestamp(dateStart.getTime()));

		// Date nextDate=WeatherDataUtil.calculateEndDate(dateStart, 1);

		int jflag = aerosolAvgMapper.insert(ga);
		flag = flag + jflag;

		return jflag;

	}

	@Override
	public int saveAvgWeek(Date dateStart,Date dateEnd,String week) {
	
			Map<String, String> map = WeatherDataUtil.getYearMonDayStr(dateStart);

			String dateStartStr=DateUtil.DateToString(dateStart, "yyyy-MM-dd HH:mm:ss");
			String nextDateStr=DateUtil.DateToString(dateEnd, "yyyy-MM-dd HH:mm:ss");	
			
			String result = aerosolAvgMapper.getAerosolAvgWeek(dateStartStr, nextDateStr);

			List<String> listStr = WeatherDataUtil.strToArrayList(result, "#");
			AerosolAvg ga = new AerosolAvg(listStr.get(0), listStr.get(1), listStr.get(2), listStr.get(3),
					listStr.get(4), listStr.get(5), listStr.get(6), listStr.get(7), listStr.get(8), listStr.get(9),
					listStr.get(10), listStr.get(11));
			ga.setDay_avg_id(IdWorker.getIdStr());
			ga.setCreate_time(DataUtil.getCurrenTimestamp());
			ga.setData_type(DataTypeEnum.Week.getValue());
			ga.setYear(map.get("year"));
			ga.setMon(map.get("mon"));
			ga.setDate_time(new Timestamp(dateStart.getTime()));
			ga.setDate_week(week);

			int jflag = aerosolAvgMapper.insert(ga);
			
		return jflag;

	}

	
	
	public Map<String, Object> getMapByFilesDayMonWeekYear(DataAvgDto groundAvgDto) {
		Map<String, Object> map = new HashMap<String, Object>();
		DataAvgDto dto = groundAvgDto;
		QueryWrapper<AerosolAvg> query = Wrappers.query();
		if (StringUtils.isNotBlank(dto.getPrs())) {
			query.select(dto.getPrs());
			query.orderByAsc("date_time");
			List<Object> list = aerosolAvgMapper.selectObjs(query);
			map.put("datas", list);
			return map;
		}

		if (StringUtils.isNotBlank(dto.getRhu())) {
			query.select(dto.getPrs());
			query.orderByAsc("date_time");
			List<Object> list = aerosolAvgMapper.selectObjs(query);
			map.put("datas", list);
			return map;
		}
		if (StringUtils.isNotBlank(dto.getTem())) {
			query.select(dto.getTem());
			query.orderByAsc("date_time");
			List<Object> list = aerosolAvgMapper.selectObjs(query);
			map.put("datas", list);
			return map;
		}

		if (StringUtils.isNotBlank(dto.getPm10_densty_fore())) {
			query.select(dto.getPm10_densty_fore());
			query.orderByAsc("date_time");
			List<Object> list = aerosolAvgMapper.selectObjs(query);
			map.put("datas", list);
			return map;
		}
		if (StringUtils.isNotBlank(dto.getPm2p5_densty())) {
			query.select(dto.getPm2p5_densty());
			query.orderByAsc("date_time");
			List<Object> list = aerosolAvgMapper.selectObjs(query);
			map.put("datas", list);
			return map;
		}

		if (StringUtils.isNotBlank(dto.getPm1_densty())) {
			query.select(dto.getPm1_densty());
			query.orderByAsc("date_time");
			List<Object> list = aerosolAvgMapper.selectObjs(query);
			map.put("datas", list);
			return map;
		}
		if (StringUtils.isNotBlank(dto.getRhu_pm1_senosr())) {
			query.select(dto.getRhu_pm1_senosr());
			query.orderByAsc("date_time");
			List<Object> list = aerosolAvgMapper.selectObjs(query);
			map.put("datas", list);
			return map;
		}
		if (StringUtils.isNotBlank(dto.getPrs_pm1_sensor())) {
			query.select(dto.getPrs_pm1_sensor());
			query.orderByAsc("date_time");
			List<Object> list = aerosolAvgMapper.selectObjs(query);
			map.put("datas", list);
			return map;
		}
		if (StringUtils.isNotBlank(dto.getTem_pm1_sensor())) {
			query.select(dto.getTem_pm1_sensor());
			query.orderByAsc("date_time");
			List<Object> list = aerosolAvgMapper.selectObjs(query);
			map.put("datas", list);
			return map;
		}
		if (StringUtils.isNotBlank(dto.getRhu_pm2p5_sensor())) {
			query.select(dto.getRhu_pm2p5_sensor());
			query.orderByAsc("date_time");
			List<Object> list = aerosolAvgMapper.selectObjs(query);
			map.put("datas", list);
			return map;
		}
		if (StringUtils.isNotBlank(dto.getPrs_pm2p5_sensor())) {
			query.select(dto.getPrs_pm2p5_sensor());
			query.orderByAsc("date_time");
			List<Object> list = aerosolAvgMapper.selectObjs(query);
			map.put("datas", list);
			return map;
		}
		if (StringUtils.isNotBlank(dto.getTem_pm2p5_sensor())) {
			query.select(dto.getTem_pm2p5_sensor());
			query.orderByAsc("date_time");
			List<Object> list = aerosolAvgMapper.selectObjs(query);
			map.put("datas", list);
			return map;
		}
		return null;
	}

	@Override
	public Map<String, Object> getAerosolAvgByFiled(DataAvgDto dataAvgDto) {

		Map<String, Object> map = new HashMap<String, Object>();
		DataAvgDto dto = dataAvgDto;
		QueryWrapper<AerosolAvg> query = Wrappers.query();

		// 判断处理那种数据类型 在判断 查询那种属性值
		// 展示的数据 类型
		if (StringUtils.isNotBlank(dto.getHour())) {
			query.eq("data_type", DataTypeEnum.Hour.getValue());

			if (StringUtils.isNotBlank(dto.getDay_who_year())) {
				
				Map<String, Object>  map1=this.getAerosolHourByFiled(dto,dto.getDay_who_year());
				if (map1 != null) {
					map.put("success", true);
					map.put("times", map1.get("times"));
					map.put("datas", map1.get("datas"));
				} else {
					map.put("success", false);
				}
				return map;

			} else {
				map.put("success", false);
				map.put("message", "查询日平均数据类型,后台没有接收到 查询年份参数");
				return map;
			}

		} else if (StringUtils.isNotBlank(dto.getDay())) {
			query.eq("data_type", DataTypeEnum.Day.getValue());

			if (StringUtils.isNotBlank(dto.getDay_who_year())) {
				query.eq("year", dto.getDay_who_year());
				// 升序排列
				List<String> listDate = aerosolAvgMapper.getDayTimeStr(DataTypeEnum.Day.getValue(),
						dto.getDay_who_year());

				// 处理各种属性 查询
				Map<String, Object> map1 = this.getMapByFilesDayMonWeekYear(dto);
				if (map1 != null) {
					map.put("success", true);
					map.put("times", listDate);
					map.put("datas", map1.get("datas"));
				} else {
					map.put("success", false);
				}
				return map;

			} else {
				map.put("success", false);
				map.put("message", "查询日平均数据类型,后台没有接收到 查询年份参数");
				return map;
			}

		} else if (StringUtils.isNotBlank(dto.getWeek())) {
			// 统计 周平均数据的 处理
			query.eq("data_type", DataTypeEnum.Week.getValue());

			if (StringUtils.isNotBlank(dto.getDay_who_year())) {
				query.eq("year", dto.getDay_who_year());
				// 升序排列
				List<String> listDate = aerosolAvgMapper.getWeekTimeStr(DataTypeEnum.Week.getValue(),
						dto.getDay_who_year());

				// 处理各种属性 查询
				Map<String, Object> map1 = this.getMapByFilesDayMonWeekYear(dto);
				if (map1 != null) {
					map.put("success", true);
					map.put("times", listDate);
					map.put("datas", map1.get("datas"));
				} else {
					map.put("success", false);
				}
				return map;

			} else {
				map.put("success", false);
				map.put("message", "查询 周平均数据类型, 后台没有接收到 查询年份参数");
				return map;
			}

		} else if (StringUtils.isNotBlank(dto.getMon())) {
			// 统计 月平均数据的 处理 月平均数据 展示所有的数据
			query.eq("data_type", DataTypeEnum.Mon.getValue());
			// 获取时间轴数据
			List<String> listDateMon = aerosolAvgMapper.getMonTimeStr(DataTypeEnum.Mon.getValue());
			// 处理各种属性 查询
			Map<String, Object> map1 = this.getMapByFilesDayMonWeekYear(dto);
			if (map1 != null) {
				map.put("success", true);
				map.put("times", listDateMon);
				map.put("datas", map1.get("datas"));
			} else {
				map.put("success", false);
			}
			return map;

		} else if (StringUtils.isNotBlank(dto.getYear())) {

			// 统计 年平均数据的 处理 月平均数据 展示所有的数据
			query.eq("data_type", DataTypeEnum.Year.getValue());

			// 获取时间轴数据
			List<String> listDateYear = aerosolAvgMapper.getYearTimeStr(DataTypeEnum.Year.getValue());
			// 处理各种属性 查询
			Map<String, Object> map1 = this.getMapByFilesDayMonWeekYear(dto);
			if (map1 != null) {
				map.put("success", true);
				map.put("times", listDateYear);
				map.put("datas", map1.get("datas"));
			} else {
				map.put("success", false);
			}
			return map;

		} else {
			map.put("success", false);
			map.put("message", "查询地面  数据类型,后台没有接收到   统计何种  数据的 参数");
			return map;
		}

	}

	@Override
	public Map<String, Object> getAerosolHourByFiled(DataAvgDto dataAvgDto, String yearStr) {
		Map<String, Object> map = new HashMap<String, Object>();
		DataAvgDto dto = dataAvgDto;
		QueryWrapper<AerosolData> query = Wrappers.query();
		
		QueryWrapper<AerosolData> queryTime = Wrappers.query();
		if (StringUtils.isNotBlank(dto.getPrs_hwc())) {
			query.select("prs");
			query.gt("prs",0.0);  //大于0.0
			query.ne("prs", 999998.0000 );
			query.ne("prs", 999999.0000 );
			query.eq("year", yearStr);
			query.orderByAsc("data_time");
			List<Object> listData = aerosolDataMapper.selectObjs(query);
			
			
			queryTime.select("DATE_FORMAT(data_time,'%Y-%m-%d %H')");
			queryTime.gt("prs",0.0);  //大于0.0
			queryTime.ne("prs", 999998.0000 );
			queryTime.ne("prs", 999999.0000 );
			queryTime.eq("year", yearStr);
			queryTime.orderByAsc("data_time");
			List<Object> listTime = aerosolDataMapper.selectObjs(queryTime);
			
			map.put("datas", listData);
			map.put("times", listTime);
			return map;
		}

		if (StringUtils.isNotBlank(dto.getAerosol_tem())) {
			query.select("tem");
			query.gt("tem",0.0);  //大于0.0
			query.ne("tem", 999998.0000 );
			query.ne("tem", 999999.0000 );
			query.eq("year", yearStr);
			query.orderByAsc("data_time");
			List<Object> listData = aerosolDataMapper.selectObjs(query);
			
			
			queryTime.select("DATE_FORMAT(data_time,'%Y-%m-%d %H')");
			queryTime.gt("tem",0.0);  //大于0.0
			queryTime.ne("tem", 999998.0000 );
			queryTime.ne("tem", 999999.0000 );
			queryTime.eq("year", yearStr);
			queryTime.orderByAsc("data_time");
			List<Object> listTime = aerosolDataMapper.selectObjs(queryTime);
			
			map.put("datas", listData);
			map.put("times", listTime);
			return map;
		}
		if (StringUtils.isNotBlank(dto.getPm10_densty_fore())) {
			query.select(dto.getPm10_densty_fore());
			query.gt(dto.getPm10_densty_fore(),0.0);  //大于0.0
			query.ne(dto.getPm10_densty_fore(), 999998.0000 );
			query.ne(dto.getPm10_densty_fore(), 999999.0000 );
			query.eq("year", yearStr);
			query.orderByAsc("data_time");
			List<Object> listData = aerosolDataMapper.selectObjs(query);
			
			
			queryTime.select("DATE_FORMAT(data_time,'%Y-%m-%d %H')");
			queryTime.gt(dto.getPm10_densty_fore(),0.0);  //大于0.0
			queryTime.ne(dto.getPm10_densty_fore(), 999998.0000 );
			queryTime.ne(dto.getPm10_densty_fore(), 999999.0000 );
			queryTime.eq("year", yearStr);
			queryTime.orderByAsc("data_time");
			List<Object> listTime = aerosolDataMapper.selectObjs(queryTime);
			
			map.put("datas", listData);
			map.put("times", listTime);
			return map;
		}

		if (StringUtils.isNotBlank(dto.getPm2p5_densty())) {
			query.select(dto.getPm2p5_densty());
			query.gt(dto.getPm2p5_densty(),0.0);  //大于0.0
			query.ne(dto.getPm2p5_densty(), 999998.0000 );
			query.ne(dto.getPm2p5_densty(), 999999.0000 );
			query.eq("year", yearStr);
			query.orderByAsc("data_time");
			List<Object> listData = aerosolDataMapper.selectObjs(query);
			
			
			queryTime.select("DATE_FORMAT(data_time,'%Y-%m-%d %H')");
			queryTime.gt(dto.getPm2p5_densty(),0.0);  //大于0.0
			queryTime.ne(dto.getPm2p5_densty(), 999998.0000 );
			queryTime.ne(dto.getPm2p5_densty(), 999999.0000 );
			queryTime.eq("year", yearStr);
			queryTime.orderByAsc("data_time");
			List<Object> listTime = aerosolDataMapper.selectObjs(queryTime);
			
			map.put("datas", listData);
			map.put("times", listTime);
			return map;
		}
		if (StringUtils.isNotBlank(dto.getPm1_densty())) {
			query.select(dto.getVap());
			query.gt(dto.getPm1_densty(),0.0);  //大于0.0
			query.ne(dto.getPm1_densty(), 999998.0000 );
			query.ne(dto.getPm1_densty(), 999999.0000 );
			query.eq("year", yearStr);
			query.orderByAsc("data_time");
			List<Object> listData = aerosolDataMapper.selectObjs(query);
			
			
			queryTime.select("DATE_FORMAT(data_time,'%Y-%m-%d %H')");
			queryTime.gt(dto.getPm1_densty(),0.0);  //大于0.0
			queryTime.ne(dto.getPm1_densty(), 999999.0000 );
			queryTime.eq("year", yearStr);
			queryTime.orderByAsc("data_time");
			List<Object> listTime = aerosolDataMapper.selectObjs(queryTime);
			
			map.put("datas", listData);
			map.put("times", listTime);
			return map;
		}

		if (StringUtils.isNotBlank(dto.getRhu_pm1_senosr())) {
			query.select(dto.getRhu_pm1_senosr());
			query.gt(dto.getRhu_pm1_senosr(),0.0);  //大于0.0
			query.ne(dto.getRhu_pm1_senosr(), 999998.0000 );
			query.ne(dto.getRhu_pm1_senosr(), 999999.0000 );
			query.eq("year", yearStr);
			query.orderByAsc("data_time");
			List<Object> listData = aerosolDataMapper.selectObjs(query);
			
			
			queryTime.select("DATE_FORMAT(data_time,'%Y-%m-%d %H')");
			queryTime.gt(dto.getRhu_pm1_senosr(),0.0);  //大于0.0
			queryTime.ne(dto.getRhu_pm1_senosr(), 999998.0000 );
			queryTime.ne(dto.getRhu_pm1_senosr(), 999999.0000 );
			queryTime.eq("year", yearStr);
			queryTime.orderByAsc("data_time");
			List<Object> listTime = aerosolDataMapper.selectObjs(queryTime);
			
			map.put("datas", listData);
			map.put("times", listTime);
			return map;
		}
		if (StringUtils.isNotBlank(dto.getPrs_pm1_sensor())) {
			query.select(dto.getPrs_pm1_sensor());
			query.gt(dto.getPrs_pm1_sensor(),0.0);  //大于0.0
			query.ne(dto.getPrs_pm1_sensor(), 999998.0000 );
			query.ne(dto.getPrs_pm1_sensor(), 999999.0000 );
			query.eq("year", yearStr);
			query.orderByAsc("data_time");
			List<Object> listData = aerosolDataMapper.selectObjs(query);
			
			
			queryTime.select("DATE_FORMAT(data_time,'%Y-%m-%d %H')");
			queryTime.gt(dto.getPrs_pm1_sensor(),0.0);  //大于0.0
			queryTime.ne(dto.getPrs_pm1_sensor(), 999998.0000 );
			queryTime.ne(dto.getPrs_pm1_sensor(), 999999.0000 );
			queryTime.eq("year", yearStr);
			queryTime.orderByAsc("data_time");
			List<Object> listTime = aerosolDataMapper.selectObjs(queryTime);
			
			map.put("datas", listData);
			map.put("times", listTime);
			return map;
		}

		if (StringUtils.isNotBlank(dto.getTem_pm1_sensor())) {
			query.select(dto.getTem_pm1_sensor());
			query.gt(dto.getTem_pm1_sensor(),0.0);  //大于0.0
			query.ne(dto.getTem_pm1_sensor(), 999998.0000 );
			query.ne(dto.getTem_pm1_sensor(), 999999.0000 );
			query.eq("year", yearStr);
			query.orderByAsc("data_time");
			List<Object> listData = aerosolDataMapper.selectObjs(query);
			
			
			queryTime.select("DATE_FORMAT(data_time,'%Y-%m-%d %H')");
			queryTime.gt(dto.getTem_pm1_sensor(),0.0);  //大于0.0
			queryTime.ne(dto.getTem_pm1_sensor(), 999998.0000 );
			queryTime.ne(dto.getTem_pm1_sensor(), 999999.0000 );
			queryTime.eq("year", yearStr);
			queryTime.orderByAsc("data_time");
			List<Object> listTime = aerosolDataMapper.selectObjs(queryTime);
			
			map.put("datas", listData);
			map.put("times", listTime);
			return map;
		}
		if (StringUtils.isNotBlank(dto.getRhu_pm2p5_sensor())) {
			query.select(dto.getRhu_pm2p5_sensor());
			query.gt(dto.getRhu_pm2p5_sensor(),0.0);  //大于0.0
			query.ne(dto.getRhu_pm2p5_sensor(), 999998.0000 );
			query.ne(dto.getRhu_pm2p5_sensor(), 999999.0000 );
			query.eq("year", yearStr);
			query.orderByAsc("data_time");
			List<Object> listData = aerosolDataMapper.selectObjs(query);
			
			
			queryTime.select("DATE_FORMAT(data_time,'%Y-%m-%d %H')");
			queryTime.gt(dto.getRhu_pm2p5_sensor(),0.0);  //大于0.0
			queryTime.ne(dto.getRhu_pm2p5_sensor(), 999998.0000 );
			queryTime.ne(dto.getRhu_pm2p5_sensor(), 999999.0000 );
			queryTime.eq("year", yearStr);
			queryTime.orderByAsc("data_time");
			List<Object> listTime = aerosolDataMapper.selectObjs(queryTime);
			
			map.put("datas", listData);
			map.put("times", listTime);
			return map;
		}
		if (StringUtils.isNotBlank(dto.getPrs_pm2p5_sensor())) {
			query.select(dto.getPrs_pm2p5_sensor());
			query.gt(dto.getPrs_pm2p5_sensor(),0.0);  //大于0.0
			query.ne(dto.getPrs_pm2p5_sensor(), 999998.0000 );
			query.ne(dto.getPrs_pm2p5_sensor(), 999999.0000 );
			query.eq("year", yearStr);
			query.orderByAsc("data_time");
			List<Object> listData = aerosolDataMapper.selectObjs(query);
			
			
			queryTime.select("DATE_FORMAT(data_time,'%Y-%m-%d %H')");
			queryTime.gt(dto.getPrs_pm2p5_sensor(),0.0);  //大于0.0
			queryTime.ne(dto.getPrs_pm2p5_sensor(), 999998.0000 );
			queryTime.ne(dto.getPrs_pm2p5_sensor(), 999999.0000 );
			queryTime.eq("year", yearStr);
			queryTime.orderByAsc("data_time");
			List<Object> listTime = aerosolDataMapper.selectObjs(queryTime);
			
			map.put("datas", listData);
			map.put("times", listTime);
			return map;
		}
		if (StringUtils.isNotBlank(dto.getTem_pm2p5_sensor())) {
			query.select(dto.getTem_pm2p5_sensor());
			query.gt(dto.getTem_pm2p5_sensor(),0.0);  //大于0.0
			query.ne(dto.getTem_pm2p5_sensor(), 999998.0000 );
			query.ne(dto.getTem_pm2p5_sensor(), 999999.0000 );
			query.eq("year", yearStr);
			query.orderByAsc("data_time");
			List<Object> listData = aerosolDataMapper.selectObjs(query);
			
			
			queryTime.select("DATE_FORMAT(data_time,'%Y-%m-%d %H')");
			queryTime.gt(dto.getTem_pm2p5_sensor(),0.0);  //大于0.0
			queryTime.ne(dto.getTem_pm2p5_sensor(), 999998.0000 );
			queryTime.ne(dto.getTem_pm2p5_sensor(), 999999.0000 );
			queryTime.eq("year", yearStr);
			queryTime.orderByAsc("data_time");
			List<Object> listTime = aerosolDataMapper.selectObjs(queryTime);
			
			map.put("datas", listData);
			map.put("times", listTime);
			return map;
		}

		return null;
	}

	@Override
	public Map<String, Object> getNextWeekMessage() {
		Map<String, Object> map=new HashMap<String,Object>();
		
		AerosolAvg ga=aerosolAvgMapper.getAerosolAvgByDataType(DataTypeEnum.Week.getValue());
		
		if( ga !=null){
			String beforWeek=ga.getDate_week();
			String week="";
			
			String year=ga.getYear();
			String nestYear=Integer.valueOf(year)+1+""+"-01-01 00:00:00";
			Date nextYearStartDate=DateUtil.StringToDate(nestYear, "yyyy-MM-dd HH:mm:ss");
			
			Date startDate=WeatherDataUtil.calculateEndDate(new Date(ga.getDate_time().getTime()), 7);
			Date endDate=WeatherDataUtil.calculateEndDate(startDate, 7);
			
			//如果 日期跨年   下一个 开始日期  为下一年的   开始日期
			if(startDate.after(nextYearStartDate) || endDate.after(nextYearStartDate)){
				map.put("success", true);
				 startDate=nextYearStartDate;
				 endDate=WeatherDataUtil.calculateEndDate(startDate, 7);
				 beforWeek="第0周";
			}
			
			//探测  是否存在 下一个 周期的统计数据
			List<String> list=aerosolDataMapper.getIdByDataTime(DateUtil.DateToString(startDate, "yyyy-MM-dd HH:mm:ss"));
			if(list.size() >=7){
				 
				String weekStr=beforWeek.substring(beforWeek.indexOf("第")+1, beforWeek.indexOf("周"));
				int nextWeek=Integer.valueOf(weekStr)+1;
				week="第"+nextWeek+"周";
				map.put("success",true);
				map.put("message", "有满足条件的统计数据");
				map.put("startDate", startDate);
				map.put("endDate", endDate);
				map.put("whatWeek",week);
				return map;
				
			}else{
				map.put("success", false);
				map.put("message", "没有满足一周的统计数据,需等待 元数据产生");
				return map;
			}
		}else{
			Date startDate=DateUtil.StringToDate("2015-09-15 00:00:00", "yyyy-MM-dd HH:mm:ss");
			Date endDate=DateUtil.StringToDate("2015-09-22 00:00:00", "yyyy-MM-dd HH:mm:ss");
			// 需要 重头开始统计数据 
			map.put("success",true);
			map.put("message", "从 2015-09-15开始统计数据");
			map.put("startDate", startDate);
			map.put("endDate", endDate);
			map.put("whatWeek","第1周");
			return map;
		}
		
		
	}

	@Override
	public Map<String, Object> getNextMonMessage() {
		Map<String, Object> map=new HashMap<String,Object>();
		AerosolAvg ga=aerosolAvgMapper.getAerosolAvgByDataType(DataTypeEnum.Mon.getValue());
		
		if( ga !=null){
			//上次 日期的 年月
			String year=ga.getYear();
			String mon=ga.getMon();
			int monInt=Integer.valueOf(mon);
			int yearInt=Integer.valueOf(year);
			
			
			//查询  两个月后的日期
			Date towDate=WeatherDataUtil.calculateEndDate(new Date(ga.getDate_time().getTime()), 63);
			
			
			
			//探测  两个月 后  是否 存在 统计数据
			List<String> list=aerosolDataMapper.getIdByDataTime(DateUtil.DateToString(towDate, "yyyy-MM-dd HH:mm:ss"));
			if(list.size() >0){
				
				mon=monInt+1+"";
				
				if(monInt == 12){
					mon="1";
					year=yearInt+1+"";
				}
				
				
				map.put("success",true);
				map.put("message", "有满足条件的统计数据");
				map.put("year", year);
				map.put("mon", mon);
				return map;
				
			}else{
				map.put("success", false);
				map.put("message", "没有满足 下月 的统计数据,需等待 元数据产生");
				return map;
			}
		}else{
			// 需要 重头开始统计数据 
			map.put("success",true);
			map.put("message", "从 2015-10-01开始统计数据");
			map.put("year", "2015");
			map.put("mon", "10");
			return map;
		}
		
	}

	@Override
	public Map<String, Object> getNextYearMessage() {
		Map<String, Object> map=new HashMap<String,Object>();
		AerosolAvg ga=aerosolAvgMapper.getAerosolAvgByDataType(DataTypeEnum.Year.getValue());
		
		if( ga !=null){
			//上次 日期的 年月
			String year=ga.getYear();
			int yearInt=Integer.valueOf(year);
			
			
			//查询  下一年后的日期
			Date nextYearDate=WeatherDataUtil.calculateEndDate(new Date(ga.getDate_time().getTime()), 733);
			
			
			
			//探测  两个月 后  是否 存在 统计数据
			List<String> list=aerosolDataMapper.getIdByDataTime(DateUtil.DateToString(nextYearDate, "yyyy-MM-dd HH:mm:ss"));
			if(list.size() >0){
				year=yearInt+1+"";
				
				map.put("success",true);
				map.put("message", "有满足条件的统计数据");
				map.put("year", year);
				return map;
				
			}else{
				map.put("success", false);
				map.put("message", "没有满足 下一年  的统计数据,需等待 元数据产生");
				return map;
			}
		}else{
			// 需要 重头开始统计数据 
			map.put("success",true);
			map.put("message", "从2016年 开始统计 年平均数据");
			map.put("year", "2016");
			return map;
		}
		
	}

}
